package voidgame.core;
import java.util.HashMap;
import java.util.Random;

public class Species{
	
	String name;
	String desc;
	HashMap<String, Boolean> flags;
	int size;//tiny, small, medium, large, huge
	Planet origin;
	
	public Species(Planet p, String n, Boolean intelligent){
		
		name=n;
		origin=p;
		
		flags = new HashMap<String, Boolean>();
		
		flags.put("inteligent", intelligent);
		
		flags.put("adapted-cold", false);
		flags.put("adapted-hot", false);
		
		flags.put("flying", false);
		flags.put("aquatic", false);
		flags.put("bipedal", false);
		flags.put("qudraped", false);
		flags.put("multi-legged", false);
		flags.put("serpentine", false);
		
		flags.put("amphibian", false);
		flags.put("mammal", false);
		flags.put("reptile", false);
		flags.put("avian", false);
		flags.put("fish", false);
		flags.put("insect", false);
		
		flags.put("herbivore", false);
		flags.put("carnivore", false);
		flags.put("omnivore", false);
		
		flags.put("aggresive", false);
		flags.put("hardy", false);
		
		flags.put("milkable", false);
		flags.put("egg-laying", false);
		flags.put("butherable", false);
		flags.put("tanable", false);
		flags.put("honey-producing", false);
		
		
		desc="";
		
		genFlags();
		
		if(!intelligent){
			appendFormName();
		}
		
	}
	
	
	private void appendFormName() {
		//This whole method needs doing properly
		
		if(flags.get("mammal")){
			if(flags.get("carnivore")){
				String[] candidates = {"Cat", "Lion", "Tiger", "Wolf", "Dog"};
				name+=" "+candidates[new Random().nextInt(candidates.length)];
			}
			else if(flags.get("herbivore")){
				String[] candidates = {"Horse", "Ox", "Goat", "Mammoth", "Antelope"};
				name+=" "+candidates[new Random().nextInt(candidates.length)];
			}
			else if(flags.get("omnivore")){
				String[] candidates = {"Monkey", "Bear", "Boar"};
				name+=" "+candidates[new Random().nextInt(candidates.length)];
			}
		}
		else if(flags.get("amphibian")){
			if(flags.get("carnivore")){
				
			}
			else if(flags.get("herbivore")){
				
			}
			else if(flags.get("omnivore")){
				
			}
		}
		else if(flags.get("reptile")){
			if(flags.get("carnivore")){
				
			}
			else if(flags.get("herbivore")){
				
			}
			else if(flags.get("omnivore")){
				
			}
		}
		else if(flags.get("avian")){
			if(flags.get("carnivore")){
				
			}
			else if(flags.get("herbivore")){
				
			}
			else if(flags.get("omnivore")){
				
			}
		}
		else if(flags.get("fish")){
			if(flags.get("carnivore")){
				
			}
			else if(flags.get("herbivore")){
				
			}
			else if(flags.get("omnivore")){
				
			}
		}
		else if(flags.get("insect")){
			if(flags.get("carnivore")){
				
			}
			else if(flags.get("herbivore")){
				
			}
			else if(flags.get("omnivore")){
				
			}
		}
	}


	public void genFlags(){
		Random ran = new Random();
		
		if(flags.get("inteligent")){
			size=ran.nextInt(3)+2;
			
			int type = ran.nextInt(6);
			switch(type){
				case 0:flags.put("mammal", true);break;
				case 1:flags.put("mammal", true);break;
				case 2:flags.put("amphibian", true);break;
				case 3:flags.put("reptile", true);break;
				case 4:flags.put("avian", true);break;
				case 5:flags.put("insect", true);break;
			}
			
		}
		else{
			size=ran.nextInt(5);
			
			int type = ran.nextInt(5);
			switch(type){
				case 0:flags.put("mammal", true);break;
				case 1:flags.put("fish", true);break;
				case 2:flags.put("amphibian", true);break;
				case 3:flags.put("reptile", true);break;
				case 4:flags.put("avian", true);break;
				case 5:flags.put("insect", true);break;
			}
		}
			
		int diet = ran.nextInt(3);
		switch(diet){
			case 0:flags.put("herbivore", true);break;
			case 1:flags.put("carnivore", true);break;
			case 2:flags.put("omnivore", true);break;
		}
		
		if(ran.nextInt(5)==0)
			flags.put("aggresive", true);
		else if(ran.nextInt(2)==0&&flags.get("carnivore"))
			flags.put("aggresive", true);
		
		if(ran.nextInt(3)>origin.temp){
			flags.put("adapted-hot", true);
			if(ran.nextInt(2)==0)
				flags.put("hardy", true);
		}
		else if((ran.nextInt(3)+2)>origin.temp){
			flags.put("adapted-cold", true);
			if(ran.nextInt(2)==0)
				flags.put("hardy", true);
		}
		
				
		int mobility=ran.nextInt(6);
		
		if(flags.get("mammal")){
			switch(mobility){
				case 0:flags.put("flying", true);flags.put("bipedal", true);break;
				case 1:flags.put("quadraped", true);break;
				case 2:flags.put("multi-legged", true);break;
				case 3:flags.put("bipedal", true);break;
				case 4:flags.put("aquatic", true);break;
				case 5:flags.put("quadraped", true);break;
			}
			if(!flags.get("inteligent")){
				if(ran.nextInt(2)==0)
					flags.put("milkable", true);
				if(ran.nextInt(2)==0)
					flags.put("butherable", true);
				if(ran.nextInt(2)==0)
					flags.put("tanable", false);
			}
		}
		else if(flags.get("fish")){
			flags.put("aquatic", true);
			if(!flags.get("inteligent")){
				if(ran.nextInt(2)==0)
					flags.put("egg-laying", true);
				if(ran.nextInt(2)==0)
					flags.put("butherable", true);
			}
		}
		else if(flags.get("amphibian")){
			flags.put("aquatic", true);
			switch(mobility){
				case 0:flags.put("serpentine", true);break;
				case 1:flags.put("quadraped", true);break;
				case 2:flags.put("quadraped", true);break;
				case 3:flags.put("multi-legged", true);break;
				case 4:flags.put("bipedal", true);break;
				case 5:flags.put("quadraped", true);break;
			}
			if(!flags.get("inteligent")){
				if(ran.nextInt(2)==0)
					flags.put("egg-laying", true);
				if(ran.nextInt(2)==0)
					flags.put("butherable", true);
				if(ran.nextInt(2)==0)
					flags.put("tanable", true);
			}
			
		}
		else if(flags.get("reptile")){
			switch(mobility){
				case 0:flags.put("serpentine", true);break;
				case 1:flags.put("aquatic", true);flags.put("quadraped", true);break;
				case 2:flags.put("quadraped", true);break;
				case 3:flags.put("bipedal", true);break;
				case 4:flags.put("flying", true);break;
				case 5:flags.put("multi-legged", true);break;
			}
			if(!flags.get("inteligent")){
				if(ran.nextInt(2)==0)
					flags.put("egg-laying", true);
				if(ran.nextInt(2)==0)
					flags.put("butherable", true);
				if(ran.nextInt(2)==0)
					flags.put("tanable", true);
			}
			
		}
		else if(flags.get("avian")){
			switch(mobility){
				case 0:flags.put("serpentine", true);flags.put("flying", true);break;
				case 1:flags.put("quadraped", true);flags.put("flying", true);break;
				case 2:flags.put("quadraped", true);break;
				case 3:flags.put("bipedal", true);flags.put("flying", true);break;
				case 4:flags.put("bipedal", true);flags.put("flying", true);break;
				case 5:flags.put("bipedal", true);break;
			}
			if(!flags.get("inteligent")){
				if(ran.nextInt(2)==0)
					flags.put("egg-laying", true);
				if(ran.nextInt(2)==0)
					flags.put("butherable", true);
				if(ran.nextInt(2)==0)
					flags.put("tanable", true);
			}
			
		}
		else if(flags.get("insect")){
			switch(mobility){
				case 0:flags.put("multi-legged", true);break;
				case 1:flags.put("quadraped", true);flags.put("flying", true);break;
				case 2:flags.put("quadraped", true);break;
				case 3:flags.put("multi-legged", true);flags.put("flying", true);break;
				case 4:flags.put("multi-legged", true);break;
				case 5:flags.put("bipedal", true);break;
			}
			if(!flags.get("inteligent")){
				if(ran.nextInt(2)==0)
					flags.put("egg-laying", true);
				if(ran.nextInt(2)==0)
					flags.put("butherable", true);
				if(ran.nextInt(2)==0)
					flags.put("tanable", true);
				if(ran.nextInt(2)==0)
					flags.put("honey-producing", true);
			}
		}
		
	}
	
}